//
//  ExtHandler.swift
//  test-ios
//
//  Created by wyz5204 on 2023/5/18.
//

import Foundation
import RxSwift

public protocol Handler {
}

extension Handler{
    
    func post(_ block: @escaping ()->Void){
        Dispatcher.dispatchClosure(delayTime: 0, block)
    }
    
    func postDelay(delayTime : TimeInterval, _ block: @escaping ()->Void){
        Dispatcher.dispatchClosure(delayTime: delayTime, block)
    }
    
}

extension NSObject: Handler {
    
    func registerNotificationObserver(name aName: NSNotification.Name, object anObject: AnyObject? = nil ,_ callback : @escaping  (Notification) -> Void){
        NotificationCenter.default.rx.notification(aName , object: anObject).subscribe(onNext: callback).disposed(by: self.rx.disposeBag)
    }
    
    func postNotificationMessage(_ aName: NSNotification.Name, object anObject: Any? = nil){
        NotificationCenter.default.post(name: aName , object: anObject)
    }
}
